package com.rinlink.jbcodec.creator;

import com.alibaba.fastjson.JSONObject;
import com.rinlink.jbcodec.JSONCodec;
import com.rinlink.jbcodec.ObjectToBytesCreatorMap;
import com.rinlink.jbcodec.common.CreatorUtils;
import com.rinlink.jbcodec.transform.CompositeTransformToBytes;
import com.rinlink.jbcodec.transform.JSONListToBytes;
import com.rinlink.jbcodec.transform.Transform;

import java.util.ArrayList;
import java.util.List;

public class JSONListToBytesCreator extends ListToBytesCreator<JSONObject> {

    private ObjectToBytesCreatorMap creatorMap;

    public JSONListToBytesCreator(ObjectToBytesCreatorMap creatorMap){
        this.creatorMap = creatorMap;
    }

    @Override
    protected Transform<byte[]> create(List<JSONObject> jsonObjects, JSONObject attr, JSONObject source) {
        JSONCodec.Scheme scheme = CreatorUtils.getScheme(attr);
        return new JSONListToBytes(jsonObjects,scheme,creatorMap);
    }

}
